import AMap from 'vue-amap'

export default function (lnglatXY) {
  var map = new AMap.Map('amap-vue', {
    resizeEnable: true,
    zoom: 18
  })
  regeocoder()
  function regeocoder () {  // 逆地理编码
    var geocoder = new AMap.Geocoder({
      radius: 1000,
      extensions: 'all'
    })
    geocoder.getAddress(lnglatXY, function (status, result) {
      if (status === 'complete' && result.info === 'OK') {
        return geocoder_CallBack(result)
      }
    })
    var marker = new AMap.Marker({  // 加点
      map: map,
      position: lnglatXY
    })
    map.setFitView()
  }

  function geocoder_CallBack (data) {
    var address = data.regeocode.formattedAddress // 返回地址描述
    return address
  }

}
